package lium.lbs.lbsim.pay.weixinpay;

import android.os.Bundle;
import android.os.Handler;
import com.cjt2325.cameralibrary.util.LogUtil;
import com.lmlibrary.Constants;
import com.lmlibrary.bean.ResponseBean;
import com.lzy.okgo.model.Response;
import lium.lbs.lbsim.bean.WXGetHttpBean;
import lium.lbs.lbsim.jgchat.activity.BaseActivity;
import lium.lbs.lbsim.listener.PayMessageEven;
import lium.lbs.lbsim.listener.SystemMessageEven;
import lium.lbs.lbsim.utils.callbck.JsonCallback;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;

public class WXPayActivity extends BaseActivity {

    private String orderSN;
    private String priceOder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    private void initView() {
        orderSN = getIntent().getStringExtra("orderSN");
        priceOder = getIntent().getStringExtra("needMoney");
        fristSign();
    }

    private void fristSign() {
        HashMap<String, String> parrmt = new HashMap<String, String>();
        parrmt.put("orderSn", orderSN);
        parrmt.put("realAmount", priceOder);
        postData("/weixinPay/weixinPay", parrmt, new JsonCallback<ResponseBean<WXGetHttpBean>>(this) {
            @Override
            public void onSuccess(Response<ResponseBean<WXGetHttpBean>> response) {
                setData(response.body().data, response.body().data.getParams().getAppId());

            }
        });
    }

    private void setData(WXGetHttpBean wBean, String getAppId) {
        setResult(250);
        WXPayUtils.WXPayBuilder builder = new WXPayUtils.WXPayBuilder();
        LogUtil.e("body---" + getAppId);
        builder.setAppId(getAppId)
                .setPartnerId(wBean.getParams().getPartnerid())
                .setPrepayId(wBean.getParams().getPrepay_id())
                .setPackageValue(wBean.getParams().getBaoguo())
                .build()
                .toWXPayAndSign(WXPayActivity.this, wBean.getParams().getAppId(), Constants.WXKEYID);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                finish();
            }
        }, 1000);


    }

}
